<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:v="http://corejsf.com/validator">

    <f:view>
        <f:loadBundle var="text" basename="#{companyForm.bundleName}"/>
        <head>
            <title>#{text['companyDetail.title']}</title>
            <meta name="heading" content="#{text['companyDetail.heading']}"/>
            <meta name="menu" content="CatalogsMenu"/>
        </head>
        
        <div class="separator"></div>

        <h:form id="companyForm">
            <h:inputHidden value="#{companyForm.company.id}" id="id"/>

            <h:panelGrid columns="3">

                <h:panelGroup styleClass="buttonBar right">
                    <h:commandButton value="#{text['button.save']}" action="#{companyForm.save}" id="save" styleClass="button"/>
                    <c:if test="${not empty companyForm.company.id}">
                        <h:commandButton value="#{text['button.delete']}" action="#{companyForm.delete}"
                                         id="delete" styleClass="button"/>
                    </c:if>
                    <h:commandButton value="#{text['button.close']}" action="cancel" immediate="true"
                                     id="cancel" styleClass="button"/>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup styleClass="info">
                    <c:choose>
                        <c:when test="${param.from == 'list' or empty companyForm.company.id}">
                            <h:outputText value="#{text['companyDetail.admin.message']}"/>
                        </c:when>
                        <c:otherwise><h:outputText value="#{text['companyDetail.message']}"/></c:otherwise>
                    </c:choose>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:outputLabel for="description" styleClass="desc" value="#{text['company.description']}"/>
                <t:message for="description" styleClass="fieldError"/>
                <h:inputText value="#{companyForm.company.description}" id="description" required="true" styleClass="text large">
                    <v:commonsValidator client="true" type="required" arg="#{text['company.description']}"/>
                </h:inputText>
              
                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="phone" value="#{text['company.phone']}"/>
                            <h:inputText styleClass="text medium" id="phone" value="#{companyForm.company.phone}"/>
                            <t:message for="phone" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="fax" value="#{text['company.fax']}"/>
                            <h:inputText styleClass="text medium" id="fax" value="#{companyForm.company.fax}"/>
                            <t:message for="fax" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:outputLabel for="address" styleClass="desc" value="#{text['company.address']}"/>
                <t:message for="address" styleClass="fieldError"/>
                <h:inputText value="#{companyForm.company.address}" id="address" styleClass="text large"/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="website" value="#{text['company.website']}"/>
                            <h:inputText styleClass="text medium" id="website" value="#{companyForm.company.website}"/>
                            <t:message for="website" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="creditDays" value="#{text['company.creditDays']}"/>
                            <h:inputText styleClass="text medium" id="creditDays" value="#{companyForm.company.creditDays}" required="true"/>
                            <t:message for="creditDays" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel for="balance" styleClass="desc" value="#{text['company.balance']}"/>
                            <h:inputText styleClass="text medium" id="balance" value="#{companyForm.balance}" readonly="true"/>
                        </div>
                        <div>
                            <h:outputLabel for="balanceLocal" styleClass="desc" value="#{text['company.balanceLocal']}"/>
                            <h:inputText styleClass="text medium" id="balanceLocal" value="#{companyForm.balanceLocal}" readonly="true"/>
                        </div>
                    </div>
                </h:panelGroup>
            </h:panelGrid>

            <t:saveState id="save1" value="#{companyForm.balanceLocal}"/>
            <t:saveState id="save2" value="#{companyForm.balance}"/>
        </h:form>

        <script type="text/javascript">
            Form.focusFirstElement($('companyForm'));
            highlightFormElements();
        </script>
    </f:view>
</html>